import plugin from '../../../lib/plugins/plugin.js';  
import fetch from 'node-fetch'  
  
export class ShortUrl extends plugin {  
  constructor () {  
    super({  
      name: '短网址查询',  
      dsc: '短网址查询服务',  
      event: 'message',  
      priority: 5000,  
      rule: [  
        {  
          reg: `^#(.*)(短网址查询)(.*)`,  
          fnc: 'shortUrlQuery'  
        },  
      ]  
    })  
  }  
  async shortUrlQuery (e) {  
    let msg = e.msg  
    let place = msg.replace(/#|短网址查询/g, "").trim();  
    let url = `https://xiaoapi.cn/API/dwz.php?url=${place}`;  
    let res = await fetch(url).catch((err) => logger.error(err))  
  
    if (!res) {  
      logger.error('[短网址查询] 接口请求失败')  
      return await this.reply('短网址查询接口请求失败,请联系主人更换接口')  
    }  
    res = await res.text()  
    await this.reply(`${res}`)  
  }  
}
